package com.victorvieux.android.handlers;

import java.util.ArrayList;

import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

import com.victorvieux.android.vlcmote.leaf;

public class PlaylistHandler extends DefaultHandler {
	private ArrayList<leaf> leafs = new ArrayList<leaf>();
	private int currentPos = 0;
	private int currentId = 0;
	private int cpt = 0;

	@Override
     public void startElement(String ns, String sName, String qName,
        Attributes attrs) throws SAXException {
		if (sName.equals("leaf"))
		{
			leafs.add(new leaf(attrs.getValue("uri"), attrs.getValue("name"), Integer.parseInt(attrs.getValue("id"))));
			if (attrs.getValue("current") != null) {
				currentPos = cpt;
				currentId = Integer.parseInt(attrs.getValue("id"));
			}	
			++cpt;
		}
     }
	
	public ArrayList<leaf> getPlaylist() {
		return leafs;
	}

	public int getCurrentPos() {
		return currentPos;
	}

	public int getCurrentId() {
		return currentId;
	}
}
